<template>
	<view>
		<!-- 已结算收益 -->
		<view class="bg-white radius" v-for="(item, index) in list" :key="index">
			<view class="margin-sm padding-tb-xs solids-bottom padding-left flex">
				<view class="basis-df">结算年月：{{ item.settleMonth | formatMonthDate }}</view>
				<view class="basis-df">
					总笔数：
					<text class="padding-right-xs">{{ orderAmount(item) }}</text>
					笔
				</view>
			</view>
			<view class="margin-sm padding-bottom-xs solids-bottom padding-left flex" v-if="showCurrencyAmount(item, 'CNY')">
				<view class="basis-df">币种：人民币</view>
				<view class="basis-df">总额：<text class="text-bold text-pink">{{currencyAmount(item,'CNY')}}</text></view>
			</view>
			<view class="margin-sm padding-bottom-xs solids-bottom padding-left flex" v-if="showCurrencyAmount(item, 'BTC')">
				<view class="basis-df">币种：BTC</view>
				<view class="basis-df">总额：<text class="text-bold text-pink">{{currencyAmount(item,'BTC')}}</text></view>
			</view>
			<view class="margin-sm padding-bottom-xs solids-bottom padding-left flex" v-if="showCurrencyAmount(item, 'ETH')">
				<view class="basis-df">币种：ETH</view>
				<view class="basis-df">总额：<text class="text-bold text-pink">{{currencyAmount(item,'ETH')}}</text></view>
			</view>
			<view class="padding-bottom-xs"></view>
		</view>
	</view>
</template>

<script>
export default {
	props: {
		list: {
			// 数据列表
			type: Array,
			default() {
				return [];
			}
		},
		rateCurrency: {
			type: String,
			default() {
				return 'CNY';
			}
		}
	},
	methods: {
		//格式化币种金额
		FixedCeilCoin(amount, currency) {
			let len = currency == 'CNY' ? 2 : currency == 'BTC' ? 8 : 6;
			return this.$util.FixedCeilCoin(amount, len);
		},
		//总返佣金额
		currencyAmount(item, currency) {
			let sum = 0;
			let p = item.product.currencyList;
			let f = item.firstUser.currencyList;
			let s = item.secondUser.currencyList;
			let tmp = p.find((item, index) => item.settleCurrency == currency);
			if (tmp) {
				sum += parseFloat(tmp.settleAmount);
			}
			tmp = f.find((item, index) => item.settleCurrency == currency);
			if (tmp) {
				sum += parseFloat(tmp.settleAmount);
			}
			tmp = s.find((item, index) => item.settleCurrency == currency);
			if (tmp) {
				sum += parseFloat(tmp.settleAmount);
			}
			return this.FixedCeilCoin(sum, currency);
		},
		//根据设定的结算币种和总金额 计算是否显示
		showCurrencyAmount(item, currency) {
			let sum = this.currencyAmount(item, currency);
			let flg = true;
			if (parseFloat(sum) == 0) {
				if (this.rateCurrency != currency) {
					flg = false;
				}
			}
			return flg;
		},
		//总订单数
		orderAmount(item) {
			let p = item.product.settleCount;
			let f = item.firstUser.settleCount;
			let s = item.secondUser.settleCount;
			return p + f + s;
		}
	},
	filters: {
		//结算币种
		CurrencyText: function(currency) {
			return currency == 'CNY' ? '人民币' : currency;
		},
		//时间戳过滤器年月
		formatMonthDate: function(value) {
			let tmp = '';
			if (value) {
				let date = new Date(value);
				let y = date.getFullYear();
				let MM = date.getMonth() + 1;
				tmp = y + '年' + MM + '月';
			}
			return tmp;
		}
	}
};
</script>
